
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>1、MEASUREMENT · turf源码算法分析</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="lijian">
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="chapter2.html" />
    
    
    <link rel="prev" href="../" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    INTRODUCE
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.2" data-path="chapter1.html">
            
                <a href="chapter1.html">
            
                    
                    1、MEASUREMENT
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="chapter2.html">
            
                <a href="chapter2.html">
            
                    
                    2、COORDINATE MUTATION
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="chapter3.html">
            
                <a href="chapter3.html">
            
                    
                    3、TRANSFORMATION
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="chapter4.html">
            
                <a href="chapter4.html">
            
                    
                    4、FEATURE CONVERSION
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="chapter5.html">
            
                <a href="chapter5.html">
            
                    
                    5、MISC
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="chapter6.html">
            
                <a href="chapter6.html">
            
                    
                    6、HELPER
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="chapter7.html">
            
                <a href="chapter7.html">
            
                    
                    7、RANDOM
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="chapter8.html">
            
                <a href="chapter8.html">
            
                    
                    8、DATA
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="chapter9.html">
            
                <a href="chapter9.html">
            
                    
                    9、INTERPOLATION
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="chapter10.html">
            
                <a href="chapter10.html">
            
                    
                    10、JOINS
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="chapter11.html">
            
                <a href="chapter11.html">
            
                    
                    11、GRIDS
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="chapter12.html">
            
                <a href="chapter12.html">
            
                    
                    12、CLASSIFICATION
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14" data-path="chapter13.html">
            
                <a href="chapter13.html">
            
                    
                    13、AGGREGATION
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15" data-path="chapter14.html">
            
                <a href="chapter14.html">
            
                    
                    14、META
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.16" data-path="chapter15.md">
            
                <span>
            
                    
                    15、ASSERTIONS
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17" data-path="chapter16.html">
            
                <a href="chapter16.html">
            
                    
                    16、BOOLEANS
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.18" data-path="chapter17.md">
            
                <span>
            
                    
                    17、UNIT CONVERSION
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >1、MEASUREMENT</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="distance">distance</h1>
<p>&#x6839;&#x636E;&#x4E24;&#x70B9;&#x7684;&#x7ECF;&#x7EAC;&#x5EA6;&#x5750;&#x6807;&#x8BA1;&#x7B97;&#x4E24;&#x70B9;&#x7684;&#x8DDD;&#x79BB;&#x91C7;&#x7528;&#x7684;&#x662F;&#x7403;&#x9762;&#x4F59;&#x5F26;&#x5B9A;&#x7406;&#x548C;&#x534A;&#x6B63;&#x77E2;&#x516C;&#x5F0F;&#xFF08;&#x8FD9;&#x91CC;&#x4F7F;&#x7528;&#x7684;&#x662F;&#x7403;&#x9762;&#x6A21;&#x578B;&#xFF09;</p>
<p>&#x53C2;&#x8003;&#xFF08;<a href="https://johnnyqian.net/blog/gps-locator/&#xFF09;" target="_blank">https://johnnyqian.net/blog/gps-locator/&#xFF09;</a></p>
<p>&#x8FD9;&#x91CC;&#x7ED9;&#x51FA;&#x5B9E;&#x73B0;&#x8FC7;&#x7A0B;&#xFF0C;&#x516C;&#x5F0F;&#x7565;&#x5FAE;&#x590D;&#x6742;&#xFF0C;&#x6700;&#x597D;&#x5148;&#x67E5;&#x770B;&#x4E0A;&#x9762;&#x7684;&#x94FE;&#x63A5;&#x770B;&#x63A8;&#x5BFC;&#x8FC7;&#x7A0B;</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// &#x7EAC;&#x5EA6;&#x5F27;&#x5EA6;&#x5DEE;&#xFF0C;&#x7528;&#x5F27;&#x5EA6;&#x8868;&#x793A;</span>
<span class="hljs-keyword">var</span> dLat = degreesToRadians((coordinates2[<span class="hljs-number">1</span>] - coordinates1[<span class="hljs-number">1</span>]));
<span class="hljs-comment">// &#x7ECF;&#x5EA6;&#x5F27;&#x5EA6;&#x5DEE;&#xFF0C;&#x7528;&#x5F27;&#x5EA6;&#x8868;&#x793A;</span>
<span class="hljs-keyword">var</span> dLon = degreesToRadians((coordinates2[<span class="hljs-number">0</span>] - coordinates1[<span class="hljs-number">0</span>]));

<span class="hljs-comment">// &#x8D77;&#x70B9;&#x7EAC;&#x5EA6;&#xFF0C;&#x7528;&#x5F27;&#x5EA6;&#x8868;&#x793A;</span>
<span class="hljs-keyword">var</span> lat1 = degreesToRadians(coordinates1[<span class="hljs-number">1</span>]);
<span class="hljs-comment">// &#x7EC8;&#x70B9;&#x7EAC;&#x5EA6;&#xFF0C;&#x7528;&#x5F27;&#x5EA6;&#x8868;&#x793A;                                                                                 </span>
<span class="hljs-keyword">var</span> lat2 = degreesToRadians(coordinates2[<span class="hljs-number">1</span>]);

<span class="hljs-comment">// &#x8FD9;&#x91CC;&#x7684;a&#x6839;&#x636E;&#x7403;&#x9762;&#x4F59;&#x5F26;&#x5B9A;&#x7406;&#x548C;&#x534A;&#x6B63;&#x77E2;&#x516C;&#x5F0F;&#x63A8;&#x7B97;&#xFF0C;&#x8868;&#x793A;sin2&#xFF08;@/2&#xFF09;&#xFF0C;@&#x8868;&#x793A;&#x4E24;&#x70B9;&#x7684;&#x7403;&#x5FC3;&#x89D2;</span>
<span class="hljs-keyword">var</span> a = <span class="hljs-built_in">Math</span>.pow(<span class="hljs-built_in">Math</span>.sin(dLat / <span class="hljs-number">2</span>), <span class="hljs-number">2</span>) +
    <span class="hljs-built_in">Math</span>.pow(<span class="hljs-built_in">Math</span>.sin(dLon / <span class="hljs-number">2</span>), <span class="hljs-number">2</span>) * <span class="hljs-built_in">Math</span>.cos(lat1) * <span class="hljs-built_in">Math</span>.cos(lat2);

<span class="hljs-comment">// &#x8FD9;&#x91CC;&#x7684;b&#x8868;&#x793A;&#x4E24;&#x70B9;&#x7684;&#x7403;&#x5FC3;&#x89D2;&#x5927;&#x5C0F;</span>
<span class="hljs-keyword">var</span> b = <span class="hljs-number">2</span> * <span class="hljs-built_in">Math</span>.atan2(<span class="hljs-built_in">Math</span>.sqrt(a), <span class="hljs-built_in">Math</span>.sqrt(<span class="hljs-number">1</span> - a));

<span class="hljs-comment">// &#x901A;&#x8FC7;&#x5F27;&#x957F;&#x516C;&#x5F0F;&#x8BA1;&#x7B97;&#x4E24;&#x70B9;&#x7684;&#x5927;&#x5706;&#x5F27;&#x957F;&#xFF0C;&#x5373;&#x4E24;&#x70B9;&#x4E4B;&#x95F4;&#x7684;&#x8DDD;&#x79BB;</span>
<span class="hljs-comment">// &#x5730;&#x7403;&#x534A;&#x5F84;&#x4E3A;6371008.8m</span>
<span class="hljs-keyword">return</span> radiansToLength(b);
</code></pre>
<p><strong>&#x5F27;&#x957F;&#x516C;&#x5F0F;</strong></p>
<p>L = a * r</p>
<p>L&#x4E3A;&#x5F27;&#x957F;&#xFF0C;a&#x4E3A;&#x89D2;&#x5EA6;(&#x5F27;&#x5EA6;&#x8868;&#x793A;)&#xFF0C;r&#x4E3A;&#x5706;&#x7684;&#x534A;&#x5F84;</p>
<p><strong>&#x5EA6;&#x8F6C;&#x5F27;&#x5EA6;</strong></p>
<p>a = d * pi / 180</p>
<p>a&#x4E3A;&#x5F27;&#x5EA6;&#x503C;&#xFF0C; d&#x4E3A;&#x89D2;&#x5EA6;&#xFF0C;pi&#x4E3A;&#x5706;&#x5468;&#x7387;</p>
<h1 id="bearing">bearing</h1>
<p><code>&#x65B9;&#x4F4D;&#x89D2;</code>&#x662F;&#x4ECE;&#x67D0;&#x70B9;&#x7684;&#x6307;&#x5317;&#x7ECF;&#x7EBF;&#x8D77;&#xFF0C;&#x4F9D;&#x987A;&#x65F6;&#x9488;&#x65B9;&#x5411;&#x5230;&#x76EE;&#x6807;&#x65B9;&#x5411;&#x7EBF;&#x4E4B;&#x95F4;&#x7684;&#x6C34;&#x5E73;&#x5939;&#x89D2;&#xFF08;&#x5982;&#x56FE;&#x6240;&#x793A;&#x3B8;&#xFF0C;&#x53EF;&#x4EE5;&#x5C06;&#x5176;&#x770B;&#x6210;&#x662F;&#x6307;&#x5357;&#x9488;&#x6240;&#x6307;&#x793A;&#x7684;&#x89D2;&#x5EA6;&#xFF09;&#xFF0C;&#x4E5F;&#x5373;&#x662F;OPN&#x5E73;&#x9762;&#x4E0E;OPQ&#x5E73;&#x9762;&#x7684;&#x6240;&#x6784;&#x6210;&#x7684;<code>&#x4E8C;&#x9762;&#x89D2;</code>&#x5927;&#x5C0F;&#x3002;&#x516C;&#x5F0F;&#x4F7F;&#x7528;&#x4E09;&#x9762;&#x89D2;&#x7684;&#x6B63;&#x5F26;&#x5B9A;&#x7406;&#x548C;&#x4E09;&#x9762;&#x89D2;&#x7684;&#x4F59;&#x5F26;&#x5B9A;&#x7406;&#x63A8;&#x5BFC;&#xFF0C;&#x8FD9;&#x91CC;&#x7ED9;&#x51FA;&#x6700;&#x7EC8;&#x7684;&#x7ED3;&#x679C;&#x516C;&#x5F0F;&#xFF0C;&#x8BE6;&#x60C5;&#x53C2;&#x8003;(&#x94FE;&#x63A5;&#x65E0;&#x6CD5;&#x6253;&#x5F00;&#x8BF7;&#x8BBF;&#x95EE;&#x6E90;&#x7801;&#xFF0C;&#x6709;&#x79BB;&#x7EBF;&#x7F51;&#x9875;)&#xFF1A;<a href="https://johnnyqian.net/blog/gps-locator/" target="_blank">https://johnnyqian.net/blog/gps-locator/</a></p>
<p>&#x7403;&#x6A21;&#x578B;&#xFF1A;</p>
<p><img src="../Image/bearing1.png" alt=""></p>
<p>&#x6700;&#x7EC8;&#x516C;&#x5F0F;&#xFF1A;</p>
<p><img src="../Image/bearing2.png" alt=""></p>
<p>&#x4E0B;&#x9762;&#x901A;&#x8FC7;javascript&#x5B9E;&#x73B0;</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// &#x8D77;&#x70B9;&#x7ECF;&#x5EA6;&#xFF0C;&#x5F27;&#x5EA6;&#x8868;&#x793A;</span>
<span class="hljs-keyword">const</span> lon1 = degreesToRadians(coordinates1[<span class="hljs-number">0</span>]);
<span class="hljs-comment">// &#x8D77;&#x70B9;&#x7EAC;&#x5EA6;&#xFF0C;&#x5F27;&#x5EA6;&#x8868;&#x793A;</span>
<span class="hljs-keyword">const</span> lon2 = degreesToRadians(coordinates2[<span class="hljs-number">0</span>]);
<span class="hljs-comment">// &#x7EC8;&#x70B9;&#x7ECF;&#x5EA6;&#xFF0C;&#x5F27;&#x5EA6;&#x8868;&#x793A;</span>
<span class="hljs-keyword">const</span> lat1 = degreesToRadians(coordinates1[<span class="hljs-number">1</span>]);
<span class="hljs-comment">// &#x7EC8;&#x70B9;&#x7EAC;&#x5EA6;&#xFF0C;&#x5F27;&#x5EA6;&#x8868;&#x793A;</span>
<span class="hljs-keyword">const</span> lat2 = degreesToRadians(coordinates2[<span class="hljs-number">1</span>]);

<span class="hljs-comment">// a&#xFF0C;b&#x4E3A;&#x63A8;&#x5BFC;&#x7684;&#x4E2D;&#x95F4;&#x8FC7;&#x7A0B;</span>
<span class="hljs-keyword">const</span> a = <span class="hljs-built_in">Math</span>.sin(lon2 - lon1) * <span class="hljs-built_in">Math</span>.cos(lat2);
<span class="hljs-keyword">const</span> b = <span class="hljs-built_in">Math</span>.cos(lat1) * <span class="hljs-built_in">Math</span>.sin(lat2) -
      <span class="hljs-built_in">Math</span>.sin(lat1) * <span class="hljs-built_in">Math</span>.cos(lat2) * <span class="hljs-built_in">Math</span>.cos(lon2 - lon1);

<span class="hljs-keyword">return</span> radiansToDegrees(<span class="hljs-built_in">Math</span>.atan2(a, b));
</code></pre>
<h1 id="along">along</h1>
<p>&#x83B7;&#x53D6;&#x6CBF;&#x7740;&#x7EBF;&#x6BB5;&#x4E00;&#x6BB5;&#x4E00;&#x5B9A;&#x8DDD;&#x79BB;&#x7684;&#x70B9;&#x5750;&#x6807;</p>
<p><strong>&#x5B9E;&#x73B0;&#x601D;&#x8DEF;</strong></p>
<ul>
<li>&#x904D;&#x5386;&#x7EBF;&#x6BB5;&#x8282;&#x70B9;&#x6570;&#x7EC4;&#xFF0C;&#x8BBE;&#x7F6E;&#x53D8;&#x91CF;&#x4FDD;&#x5B58;&#x904D;&#x5386;&#x7684;&#x8DDD;&#x79BB;<ul>
<li>&#x5982;&#x679C;&#x7ED9;&#x51FA;&#x7684;&#x8DDD;&#x79BB;&#x8D85;&#x51FA;&#x7EBF;&#x6BB5;&#x957F;&#x5EA6;&#xFF0C;&#x5219;&#x8FD4;&#x56DE;&#x6700;&#x540E;&#x4E00;&#x4E2A;&#x8282;&#x70B9;</li>
<li>&#x5982;&#x679C;&#x7ED9;&#x51FA;&#x7684;&#x8DDD;&#x79BB;&#x6CA1;&#x6709;&#x8D85;&#x51FA;&#x7EBF;&#x6BB5;&#x957F;&#x5EA6;<ul>
<li>&#x904D;&#x5386;&#x7684;&#x8DDD;&#x79BB;&#x5C0F;&#x4E8E;&#x7ED9;&#x5B9A;&#x957F;&#x5EA6;&#xFF0C;&#x5219;&#x7EE7;&#x7EED;&#x904D;&#x5386;</li>
<li>&#x904D;&#x5386;&#x7684;&#x8DDD;&#x79BB;&#x7B49;&#x4E8E;&#x7ED9;&#x5B9A;&#x957F;&#x5EA6;&#xFF0C;&#x8FD4;&#x56DE;&#x8BE5;&#x8282;&#x70B9;</li>
<li>&#x904D;&#x5386;&#x7684;&#x8DDD;&#x79BB;&#x5927;&#x4E8E;&#x7ED9;&#x5B9A;&#x957F;&#x5EA6;&#xFF0C;&#x5219;&#x51CF;&#x53BB;&#x8D85;&#x51FA;&#x7684;&#x90E8;&#x5206;&#xFF0C;&#x8FD4;&#x56DE;&#x8282;&#x70B9;</li>
</ul>
</li>
</ul>
</li>
</ul>
<pre><code class="lang-javascript"><span class="hljs-comment">// &#x83B7;&#x53D6;geojson&#x4E2D;&#x7EBF;&#x6BB5;&#x7684;&#x8282;&#x70B9;&#x5750;&#x6807;&#x6570;&#x7EC4;</span>
<span class="hljs-keyword">const</span> geom = getGeom(line);
<span class="hljs-keyword">const</span> coords = geom.coordinates;
<span class="hljs-comment">// &#x4FDD;&#x5B58;&#x904D;&#x5386;&#x7684;&#x8DDD;&#x79BB;</span>
<span class="hljs-keyword">let</span> travelled = <span class="hljs-number">0</span>;
<span class="hljs-comment">// &#x904D;&#x5386;&#x5750;&#x6807;&#x6570;&#x7EC4;</span>
<span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> i = <span class="hljs-number">0</span>; i &lt; coords.length; i++) {
      <span class="hljs-comment">// &#x7ED9;&#x5B9A;&#x8DDD;&#x79BB;&#x5927;&#x4E8E;&#x7EBF;&#x6BB5;&#x957F;&#x5EA6;</span>
    <span class="hljs-keyword">if</span> (distance &gt;= travelled &amp;&amp; i === coords.length - <span class="hljs-number">1</span>) { 
      <span class="hljs-keyword">break</span>;
    } 
    <span class="hljs-comment">// &#x904D;&#x5386;&#x7684;&#x8DDD;&#x79BB;&#x5927;&#x4E8E;&#x7B49;&#x4E8E;&#x7EBF;&#x6BB5;&#x957F;&#x5EA6;</span>
      <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (travelled &gt;= distance) {
      <span class="hljs-keyword">const</span> overshot = distance - travelled;
      <span class="hljs-comment">// &#x904D;&#x5386;&#x7684;&#x8DDD;&#x79BB;&#x7B49;&#x4E8E;&#x7EBF;&#x6BB5;&#x957F;&#x5EA6;</span>
      <span class="hljs-keyword">if</span> (!overshot) { 
        <span class="hljs-keyword">return</span> point(coords[i]);
      } 
      <span class="hljs-comment">// &#x904D;&#x5386;&#x7684;&#x8DDD;&#x79BB;&#x5927;&#x4E8E;&#x7EBF;&#x6BB5;&#x7684;&#x957F;&#x5EA6;&#xFF0C;&#x5219;&#x622A;&#x53D6;</span>
      <span class="hljs-keyword">else</span> {
        <span class="hljs-comment">// bearing &#x4E3A;&#x8BA1;&#x7B97;&#x4E24;&#x70B9;&#x7684;&#x89D2;&#x5EA6;</span>
        <span class="hljs-keyword">const</span> direction = bearing(coords[i], coords[i - <span class="hljs-number">1</span>]) - <span class="hljs-number">180</span>;
        <span class="hljs-comment">// destination&#x4E3A;&#x5728;&#x7ED9;&#x5B9A;&#x70B9;&#x4E00;&#x5B9A;&#x89D2;&#x5EA6;&#x548C;&#x548C;&#x8DDD;&#x79BB;&#x7684;&#x4E00;&#x4E2A;&#x70B9;</span>
        <span class="hljs-keyword">const</span> interpolated = destination(coords[i], overshot, direction);
        <span class="hljs-keyword">return</span> interpolated;
      }
    }
   <span class="hljs-comment">// &#x904D;&#x5386;&#x7684;&#x8DDD;&#x79BB;&#x5C0F;&#x4E8E;&#x7EBF;&#x6BB5;&#x957F;&#x5EA6;</span>
      <span class="hljs-keyword">else</span> {
        travelled += distance(coords[i], coords[i + <span class="hljs-number">1</span>]);
    }
}
<span class="hljs-keyword">return</span> coords[coords.length - <span class="hljs-number">1</span>];
</code></pre>
<h1 id="area">area</h1>
<blockquote>
<p>GeoJSON&#x683C;&#x5F0F;&#x7684;polygon&#x662F;&#x4E09;&#x7EF4;&#x6570;&#x7EC4;&#x8868;&#x793A;&#xFF0C;&#x5176;&#x5B9E;&#x5982;&#x679C;&#x4EC5;&#x4EC5;&#x4FDD;&#x5B58;&#x591A;&#x8FB9;&#x5F62;&#x7684;&#x5404;&#x4E2A;&#x8282;&#x70B9;&#x7684;&#x5750;&#x6807;&#x53EA;&#x9700;&#x8981;&#x4E8C;&#x7EF4;&#x6570;&#x7EC4;&#x5C31;&#x53EF;&#x4EE5;&#x4E86;&#xFF0C;&#x4E3A;&#x4EC0;&#x4E48;&#x8FD8;&#x9700;&#x8981;&#x6709;&#x4E09;&#x7EF4;&#x5462;&#xFF1F;&#x8FD9;&#x662F;&#x56E0;&#x4E3A;&#x9542;&#x7A7A;&#x591A;&#x8FB9;&#x5F62;&#x7684;&#x5B58;&#x5728;&#xFF0C;&#x5C31;&#x662F;&#x591A;&#x8FB9;&#x5F62;&#x4E0D;&#x662F;&#x5B9E;&#x5FC3;&#x7684;&#xFF0C;&#x91CC;&#x9762;&#x6709;&#x4E00;&#x4E2A;&#x591A;&#x8FB9;&#x5F62;&#x7684;&#x533A;&#x57DF;&#x4E0D;&#x5B58;&#x5728;&#x3002;&#x5728;&#x8FD9;&#x4E2A;&#x4E09;&#x7EF4;&#x6570;&#x7EC4;&#x7684;&#x7B2C;&#x4E00;&#x7EF4;&#x4E2D;&#x4E00;&#x822C;&#x662F;&#x4E00;&#x4E2A;&#x6570;&#x7EC4;&#xFF0C;&#x5982;&#x679C;&#x51FA;&#x73B0;&#x591A;&#x4E2A;&#x6570;&#x7EC4;&#x5C31;&#x8BF4;&#x660E;&#x6709;&#x9542;&#x7A7A;&#x591A;&#x8FB9;&#x5F62;&#x7684;&#x5B58;&#x5728;&#xFF0C;&#x7B2C;&#x4E00;&#x4E2A;&#x6570;&#x7EC4;&#x662F;&#x5916;&#x591A;&#x8FB9;&#x5F62;&#xFF0C;&#x540E;&#x9762;&#x7684;&#x6570;&#x7EC4;&#x662F;&#x5185;&#x591A;&#x8FB9;&#x5F62;&#x3002;</p>
</blockquote>
<pre><code class="lang-json">{
    <span class="hljs-string">&quot;type&quot;</span>: <span class="hljs-string">&quot;Polygon&quot;</span>,
    <span class="hljs-string">&quot;coordinates&quot;</span>: [
        [
            [<span class="hljs-number">41</span>, <span class="hljs-number">55</span>],
            [<span class="hljs-number">95</span>, <span class="hljs-number">55</span>],
            [<span class="hljs-number">95</span>, <span class="hljs-number">33</span>],
            [<span class="hljs-number">41</span>, <span class="hljs-number">33</span>],
            [<span class="hljs-number">41</span>, <span class="hljs-number">55</span>]
        ]    
    ]
}
<span class="hljs-comment">// &#x4E0A;&#x9762;&#x662F;&#x4E00;&#x4E2A;&#x7B80;&#x5355;&#x7684;Polygon</span>
<span class="hljs-comment">// &#x4E0B;&#x9762;&#x662F;&#x4E00;&#x4E2A;&#x9542;&#x7A7A;&#x7684;&#x591A;&#x8FB9;&#x5F62;</span>
{
    <span class="hljs-string">&quot;type&quot;</span>: <span class="hljs-string">&quot;Polygon&quot;</span>,
    <span class="hljs-string">&quot;coordinates&quot;</span>: [
        [
            [<span class="hljs-number">41</span>, <span class="hljs-number">55</span>],
            [<span class="hljs-number">95</span>, <span class="hljs-number">55</span>],
            [<span class="hljs-number">95</span>, <span class="hljs-number">33</span>],
            [<span class="hljs-number">41</span>, <span class="hljs-number">33</span>],
            [<span class="hljs-number">41</span>, <span class="hljs-number">55</span>]
        ],
        [
            [<span class="hljs-number">54</span>, <span class="hljs-number">40</span>],
            [<span class="hljs-number">68</span>, <span class="hljs-number">44</span>],
            [<span class="hljs-number">80</span>, <span class="hljs-number">40</span>],
            [<span class="hljs-number">54</span>, <span class="hljs-number">40</span>]
        ]
    ]
}
</code></pre>
<p>&#x8BA1;&#x7B97;&#x591A;&#x8FB9;&#x5F62;&#x9762;&#x79EF;&#x516C;&#x5F0F;&#xFF1A;</p>
<p>&#x200B;    S = S1 - &#xFF08;S2 + S3 + ... + Sn&#xFF09;;</p>
<p>S&#x4E3A;&#x591A;&#x8FB9;&#x5F62;&#x7684;&#x9762;&#x79EF;&#xFF0C;S1&#x4E3A;&#x6700;&#x5916;&#x9762;&#x7684;&#x591A;&#x8FB9;&#x5F62;&#x9762;&#x79EF;&#xFF0C;&#x5728;GeoJSON&#x4E2D;&#x5BF9;&#x5E94;coordinates&#x6570;&#x7EC4;&#x7684;&#x7B2C;&#x4E00;&#x4E2A;&#x5143;&#x7D20;&#xFF0C;S2&#x5230;Sn&#x662F;&#x5185;&#x90E8;&#x7684;&#x591A;&#x8FB9;&#x5F62;&#x9762;&#x79EF;&#xFF0C;&#x5728;GeoJSON&#x4E2D;&#x5BF9;&#x5E94;coordinates&#x6570;&#x7EC4;&#x7684;&#x7B2C;&#x4E8C;&#x4E2A;&#x5230;&#x7B2C;n&#x4E2A;&#x5143;&#x7D20;&#x3002;</p>
<p>&#x53EF;&#x4EE5;&#x53D1;&#x73B0;&#xFF0C;&#x8BA1;&#x7B97;&#x9542;&#x7A7A;&#x591A;&#x8FB9;&#x5F62;&#x7684;&#x9762;&#x79EF;&#x53EF;&#x4EE5;&#x5206;&#x89E3;&#x4E3A;&#x8BA1;&#x7B97;&#x7B80;&#x5355;&#x591A;&#x8FB9;&#x5F62;&#x7684;&#x9762;&#x79EF;&#xFF0C;&#x8FD9;&#x91CC;&#x7ED9;&#x51FA;&#x7B80;&#x5355;&#x591A;&#x8FB9;&#x5F62;&#x9762;&#x79EF;&#x8BA1;&#x7B97;&#x65B9;&#x6CD5;&#x3002;</p>
<p>&#x8BA1;&#x7B97;&#x516C;&#x5F0F;</p>
<p><img src="../Image/area.png" alt="&#x9762;&#x79EF;&#x8BA1;&#x7B97;&#x516C;&#x5F0F;"></p>
<p>&#x516C;&#x5F0F;&#x4E2D;t&#x8868;&#x793A;&#x7EAC;&#x5EA6;&#xFF0C;n&#x8868;&#x793A;&#x7ECF;&#x5EA6;&#xFF0C;R&#xFF08;&#x8FD9;&#x91CC;&#x53D6;6378137m&#xFF09;&#x662F;&#x5730;&#x7403;&#x534A;&#x5F84;&#xFF0C;m&#x662F;&#x591A;&#x8FB9;&#x5F62;&#x8282;&#x70B9;&#x7684;&#x4E2A;&#x6570;</p>
<p>&#x4E3E;&#x4E2A;&#x6817;&#x5B50;&#xFF1A;</p>
<pre><code class="lang-json"><span class="hljs-comment">// &#x4E00;&#x4E2A;&#x591A;&#x8FB9;&#x5F62;&#xFF1A;</span>
{
    <span class="hljs-string">&quot;type&quot;</span>: <span class="hljs-string">&quot;Feature&quot;</span>,
    <span class="hljs-string">&quot;geometry&quot;</span>: {
        <span class="hljs-string">&quot;type&quot;</span>: <span class="hljs-string">&quot;Polygon&quot;</span>,
        <span class="hljs-string">&quot;coordinates&quot;</span>: [
            [
                [n1, t1],
                [n2, t2],
                [n3, t3],
                [n4, t4]
            ]
        ]
    }
}
<span class="hljs-comment">// &#x90A3;&#x4E48;&#x5B83;&#x7684;&#x9762;&#x79EF;&#x4E3A;&#xFF1A;</span>
<span class="hljs-comment">// S = [(n2 - n4) * sint1 + (n3 - n1) * sint2 + (n4 - n2) * sint3 + (n1 - n3) * sint4] * R * R / 2;</span>
</code></pre>
<h1 id="bbox">bbox</h1>
<p>&#x83B7;&#x53D6;&#x51E0;&#x4F55;&#x8981;&#x7D20;&#xFF08;&#x7EBF;&#x3001;&#x9762;&#xFF09;&#x7684;&#x8303;&#x56F4;&#x6570;&#x636E;&#xFF0C;&#x7ED3;&#x679C;&#x4E3A;&#x6570;&#x7EC4;[ minX, minY, maxX, maxY]</p>
<p>&#x5B9E;&#x73B0;&#x601D;&#x8DEF;&#xFF1A;</p>
<ul>
<li>&#x58F0;&#x660E;&#x53D8;&#x91CF;&#xFF0C;&#x4FDD;&#x5B58;&#x7ED3;&#x679C;&#x503C;</li>
<li>&#x904D;&#x5386;&#x51E0;&#x4F55;&#x8981;&#x7D20;&#x8282;&#x70B9;&#xFF0C;&#x4E0E;&#x53D8;&#x91CF;&#x6BD4;&#x8F83;&#xFF0C;&#x66F4;&#x65B0;&#x53D8;&#x91CF;</li>
</ul>
<p>&#x5B9E;&#x73B0;&#x8FC7;&#x7A0B;</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// &#x58F0;&#x660E;&#x53D8;&#x91CF;&#xFF0C;Infinity&#x8868;&#x793A;&#x65E0;&#x7A77;&#x5927;&#x503C;</span>
<span class="hljs-keyword">const</span> result = [<span class="hljs-literal">Infinity</span>, <span class="hljs-literal">Infinity</span>, -<span class="hljs-literal">Infinity</span>, -<span class="hljs-literal">Infinity</span>];
<span class="hljs-comment">// &#x904D;&#x5386;&#x51E0;&#x4F55;&#x8981;&#x7D20;&#x8282;&#x70B9;&#x6570;&#x7EC4;</span>
arr.forEach( coord =&gt; {
    <span class="hljs-comment">// &#x8282;&#x70B9;&#x7684;&#x7ECF;&#x5EA6;&#x3001;&#x7EAC;&#x5EA6;&#x5C0F;&#x4E8E;&#x53D8;&#x91CF;</span>
    <span class="hljs-keyword">if</span> (result[<span class="hljs-number">0</span>] &gt; coord[<span class="hljs-number">0</span>]) { result[<span class="hljs-number">0</span>] = coord[<span class="hljs-number">0</span>]; }
    <span class="hljs-keyword">if</span> (result[<span class="hljs-number">1</span>] &gt; coord[<span class="hljs-number">1</span>]) { result[<span class="hljs-number">1</span>] = coord[<span class="hljs-number">1</span>]; }
    <span class="hljs-comment">// &#x8282;&#x70B9;&#x7684;&#x7ECF;&#x5EA6;&#x3001;&#x7EAC;&#x5EA6;&#x5927;&#x4E8E;&#x53D8;&#x91CF;</span>
    <span class="hljs-keyword">if</span> (result[<span class="hljs-number">2</span>] &lt; coord[<span class="hljs-number">0</span>]) { result[<span class="hljs-number">2</span>] = coord[<span class="hljs-number">0</span>]; }
    <span class="hljs-keyword">if</span> (result[<span class="hljs-number">3</span>] &lt; coord[<span class="hljs-number">1</span>]) { result[<span class="hljs-number">3</span>] = coord[<span class="hljs-number">1</span>]; }
});
<span class="hljs-keyword">return</span> result;
</code></pre>
<h1 id="center">center</h1>
<p>&#x83B7;&#x53D6;&#x591A;&#x8FB9;&#x5F62;&#x5305;&#x542B;&#x5757;&#x4E2D;&#x5FC3;&#x70B9;&#x5750;&#x6807;&#x3002;</p>
<p>&#x5728;&#x83B7;&#x53D6;bbox&#x7684;&#x57FA;&#x7840;&#x4E0A;&#x901A;&#x8FC7;&#x5BF9;&#x7ECF;&#x7EAC;&#x7684;&#x53D6;&#x5E73;&#x5747;&#x503C;&#x53EF;&#x5F97;&#x5230;&#x4E2D;&#x5FC3;&#x70B9;&#x5750;&#x6807;&#xFF0C;&#x53C2;&#x8003;bbox&#x7684;&#x7B97;&#x6CD5;&#x3002;</p>
<p>&#x7B97;&#x6CD5;&#xFF1A;</p>
<p>bbox&#x7ED3;&#x679C;&#x4E3A;&#xFF1A; [minX, minY, maxX, maxY]</p>
<p>center&#x7684;&#x7ECF;&#x5EA6;&#xFF1A;lon = &#xFF08;minX+ maxX&#xFF09;/ 2;</p>
<p>center&#x7684;&#x7EAC;&#x5EA6;&#xFF1A;lat = &#xFF08;minY + maxY&#xFF09;/ 2;</p>
<h1 id="centerid">centerid</h1>
<blockquote>
<p>centerid&#x4E0E;center&#x7684;&#x533A;&#x522B;&#xFF1A;</p>
<p>1&#x3001;&#x8861;&#x91CF;&#x4E00;&#x4E2A;&#x591A;&#x8FB9;&#x5F62;&#x4E2D;&#x5FC3;&#x70B9;&#x7684;&#x4E0D;&#x540C;&#x5C3A;&#x5EA6;</p>
<p>2&#x3001;&#x90FD;&#x5B58;&#x5728;&#x70B9;&#x4E0D;&#x5728;&#x591A;&#x8FB9;&#x5F62;&#x5185;&#x90E8;&#x7684;&#x60C5;&#x51B5;</p>
</blockquote>
<p>&#x83B7;&#x53D6;&#x591A;&#x8FB9;&#x5F62;&#x6240;&#x6709;&#x8282;&#x70B9;&#x4E2D;&#x5FC3;&#x70B9;&#x5750;&#x6807;&#x3002;</p>
<p>&#x83B7;&#x53D6;&#x6240;&#x6709;&#x591A;&#x8FB9;&#x5F62;&#x8282;&#x70B9;&#x6A2A;&#x7EB5;&#x5750;&#x6807;&#x5E73;&#x5747;&#x503C;&#xFF0C;&#x516C;&#x5F0F;&#x4E3A;</p>
<p><img src="../Image/Snipaste_2020-06-16_14-00-20.png" alt="image-20200616135735270"></p>
<p>Xi,Yi&#x4E3A;&#x5750;&#x6807;&#x70B9;&#x7684;&#x7ECF;&#x5EA6;&#x3001;&#x7EAC;&#x5EA6;&#xFF0C;X&#x4E3A;centerid&#x7ECF;&#x5EA6;&#xFF0C;Y&#x4E3A;centerid&#x7EAC;&#x5EA6;</p>
<h1 id="destination">destination</h1>
<p>&#x7ED9;&#x5B9A;&#x4E00;&#x4E2A;&#x70B9;&#x548C;&#x8DDD;&#x79BB;&#x3001;&#x65B9;&#x4F4D;&#xFF0C;&#x6C42;&#x53E6;&#x4E00;&#x4E2A;&#x70B9;&#x7684;&#x5750;&#x6807;&#x3002;</p>
<p>&#x7B97;&#x6CD5;&#x91C7;&#x7528;&#x534A;&#x6B63;&#x77E2;&#x516C;&#x5F0F;&#x63A8;&#x5BFC;&#xFF0C;</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// &#x8D77;&#x70B9;&#x7ECF;&#x5EA6;&#xFF0C;&#x5F27;&#x5EA6;&#x8868;&#x793A;</span>
<span class="hljs-keyword">const</span> longitude1 = degreesToRadians(coordinates1[<span class="hljs-number">0</span>]);
<span class="hljs-comment">// &#x8D77;&#x70B9;&#x7EAC;&#x5EA6;&#xFF0C;&#x5F27;&#x5EA6;&#x8868;&#x793A;</span>
<span class="hljs-keyword">const</span> latitude1 = degreesToRadians(coordinates1[<span class="hljs-number">1</span>]);
<span class="hljs-comment">// &#x4EE5;&#x6B63;&#x5317;&#x4E3A;0&#x5EA6;&#xFF0C;&#x987A;&#x65F6;&#x9488;&#x65B9;&#x5411;&#x7684;&#x89D2;&#x5EA6;&#xFF0C;&#x5F27;&#x5EA6;&#x8868;&#x793A;</span>
<span class="hljs-keyword">const</span> bearingRad = degreesToRadians(bearing);
<span class="hljs-comment">// &#x76F8;&#x5DEE;&#x7684;&#x8DDD;&#x79BB;&#xFF0C;&#x5F27;&#x5EA6;&#x8868;&#x793A;</span>
<span class="hljs-keyword">const</span> radians = lengthToRadians(distance, options.units);

<span class="hljs-comment">// &#x76EE;&#x6807;&#x70B9;&#x7EAC;&#x5EA6;&#x503C;</span>
<span class="hljs-keyword">const</span> latitude2 = <span class="hljs-built_in">Math</span>.asin(<span class="hljs-built_in">Math</span>.sin(latitude1) * <span class="hljs-built_in">Math</span>.cos(radians) +
                            <span class="hljs-built_in">Math</span>.cos(latitude1) * <span class="hljs-built_in">Math</span>.sin(radians) * <span class="hljs-built_in">Math</span>.cos(bearingRad));

<span class="hljs-comment">// &#x76EE;&#x6807;&#x70B9;&#x7ECF;&#x5EA6;&#x503C;</span>
<span class="hljs-keyword">const</span> longitude2 = longitude1 + <span class="hljs-built_in">Math</span>.atan2(<span class="hljs-built_in">Math</span>.sin(bearingRad) * <span class="hljs-built_in">Math</span>.sin(radians) * <span class="hljs-built_in">Math</span>.cos(latitude1),
                                           <span class="hljs-built_in">Math</span>.cos(radians) - <span class="hljs-built_in">Math</span>.sin(latitude1) * <span class="hljs-built_in">Math</span>.sin(latitude2));
<span class="hljs-keyword">const</span> lng = radiansToDegrees(longitude2);
<span class="hljs-keyword">const</span> lat = radiansToDegrees(latitude2);

<span class="hljs-keyword">return</span> point([lng, lat], options.properties);
</code></pre>
<p><strong>&#x5F27;&#x957F;&#x8F6C;&#x4E3A;&#x5F27;&#x5EA6;</strong></p>
<p>a = L / r</p>
<p>a&#x4E3A;&#x5F27;&#x5EA6;&#xFF0C;L&#x4E3A;&#x5F27;&#x957F;&#xFF0C; r&#x4E3A;&#x5730;&#x7403;&#x534A;&#x5F84;</p>
<h1 id="centerofmass">centerOfMass</h1>
<p>&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x591A;&#x8FB9;&#x5F62;&#x7684;&#x7684;&#x8D28;&#x5FC3;&#xFF0C;&#x8FD9;&#x4E2A;&#x548C;center&#x4E0D;&#x4E00;&#x6837;&#xFF0C;center&#x6307;&#x7684;&#x662F;&#x6307;&#x5305;&#x542B;&#x591A;&#x8FB9;&#x5F62;&#x6700;&#x5C0F;&#x77E9;&#x5F62;&#x7684;&#x4E2D;&#x5FC3;&#xFF0C;&#x800C;centerOfMass&#x6307;&#x7684;&#x662F;&#x7269;&#x7406;&#x610F;&#x4E49;&#x4E0A;&#x7684;&#x8D28;&#x91CF;&#x96C6;&#x4E2D;&#x70B9;&#x3002;&#x62FF;&#x4E00;&#x4E2A;&#x76F4;&#x89D2;&#x4E09;&#x89D2;&#x5F62;&#x6765;&#x770B;&#xFF0C;&#x8FD9;&#x4E2A;&#x4E09;&#x89D2;&#x5F62;&#x7684;center&#x4F4D;&#x4E8E;&#x659C;&#x8FB9;&#x4E0A;&#xFF08;&#x5404;&#x8FB9;&#x5782;&#x76F4;&#x5E73;&#x5206;&#x7EBF;&#x4EA4;&#x70B9;&#xFF09;&#xFF0C;&#x800C;centerOfMass&#x4F4D;&#x4E8E;&#x4E09;&#x89D2;&#x5F62;&#x5185;&#x90E8;&#xFF08;&#x5404;&#x8FB9;&#x4E2D;&#x7EBF;&#x4EA4;&#x70B9;&#xFF09;&#x3002;</p>
<p>&#x516C;&#x5F0F;&#xFF1A;</p>
<p>&#x591A;&#x8FB9;&#x5F62;n&#x4E2A;&#x8282;&#x70B9;&#x4E3A;&#xFF08;x0,y0&#xFF09;,(x1,y1),(x2,y2),...,(xn-1,yn-1), &#x8D28;&#x5FC3;&#x70B9;&#x4E3A;(Cx, Cy)</p>
<p><img src="../Image/centerofmass1.png" alt=""></p>
<p><img src="../Image/centerofmass2.png" alt="centerofmass2"></p>
<p>A&#x662F;&#x8BA1;&#x7B97;&#x591A;&#x8FB9;&#x5F62;&#x7684;&#x9762;&#x79EF;&#x516C;&#x5F0F;&#xFF0C;&#x4E5F;&#x53EB;&#x978B;&#x5E26;&#x516C;&#x5F0F;&#x3002;</p>
<h1 id="length">length</h1>
<p>&#x83B7;&#x53D6;&#x7EBF;&#x6BB5;&#x957F;&#x5EA6;</p>
<p>&#x5B9E;&#x73B0;&#x8FC7;&#x7A0B;&#xFF1A;</p>
<ul>
<li>&#x904D;&#x5386;&#x7EBF;&#x6BB5;&#x5BF9;&#x8C61;&#x8282;&#x70B9;</li>
<li>&#x7D2F;&#x52A0;&#x7EBF;&#x6BB5;&#x8DDD;&#x79BB;&#xFF0C;&#x8DDD;&#x79BB;&#x516C;&#x5F0F;&#x53C2;&#x8003;[distance]</li>
</ul>
<h1 id="midpoint">midpoint</h1>
<p>&#x8BA1;&#x7B97;&#x4E24;&#x4E2A;&#x70B9;&#x7684;&#x4E2D;&#x70B9;</p>
<p>&#x4E2D;&#x70B9;&#x7684;&#x8BA1;&#x7B97;&#x65B9;&#x6CD5;&#x5176;&#x5B9E;&#x53EA;&#x9700;&#x8981;&#x53D6;&#x7ECF;&#x7EAC;&#x5EA6;&#x7684;&#x5E73;&#x5747;&#x6570;&#x5C31;&#x53EF;&#x4EE5;&#x4E86;&#xFF0C;&#x53EF;&#x662F;&#x4ECE;&#x610F;&#x4E49;&#x4E0A;&#x6765;&#x8BF4;&#xFF0C;&#x53D6;&#x5E73;&#x5747;&#x6570;&#x7684;&#x65B9;&#x6CD5;&#x662F;&#x5E94;&#x7528;&#x5728;&#x5E73;&#x9762;&#x51E0;&#x4F55;&#x4E0A;&#xFF0C;&#x8FD9;&#x91CC;&#x4F7F;&#x7528;&#x7684;&#x65B9;&#x6CD5;&#x662F;&#x8FD9;&#x6837;&#xFF1A;</p>
<ul>
<li>&#x83B7;&#x53D6;&#x4E24;&#x70B9;A&#x3001;B&#x7684;&#x7403;&#x9762;&#x8DDD;&#x79BB;distance</li>
<li>&#x83B7;&#x53D6;B&#x70B9;&#x76F8;&#x5BF9;&#x4E8E;A&#x70B9;&#x7684;&#x65B9;&#x4F4D;&#x89D2;bearing</li>
<li>&#x4F7F;&#x7528;destination&#x65B9;&#x6CD5;&#x5E26;&#x5165;A&#x70B9;&#x5750;&#x6807;&#xFF0C;distance&#x548C;bearing&#x8BA1;&#x7B97;&#x4E2D;&#x70B9;</li>
</ul>
<p>&#x8FD9;&#x6837;&#x4F7F;&#x7528;&#x7684;&#x7403;&#x9762;&#x51E0;&#x4F55;&#x7684;&#x65B9;&#x6CD5;&#xFF0C;&#x53D6;&#x5F97;&#x7684;&#x7ED3;&#x679C;&#x662F;&#x5E73;&#x5747;&#x6570;&#x7684;&#x8FD1;&#x4F3C;&#x503C;&#x3002;</p>
<h1 id="pointonfeature">pointOnFeature</h1>
<p>&#x83B7;&#x53D6;&#x4E00;&#x4E2A;&#x5728;&#x8981;&#x7D20;&#x5185;&#x90E8;&#x7684;&#x70B9;&#xFF0C;&#x4EE5;Polygon&#x4E3E;&#x4F8B;&#x3002;</p>
<p><strong>&#x5B9E;&#x73B0;&#x8FC7;&#x7A0B;&#xFF1A;</strong></p>
<ol>
<li>&#x83B7;&#x53D6;Polygon&#x4E2D;&#x5FC3;&#x70B9;centerid</li>
<li>&#x5982;&#x679C;&#x4E2D;&#x5FC3;&#x70B9;&#x5728;Polygon&#x5185;&#x90E8;&#xFF0C;&#x5219;&#x8FD4;&#x56DE;&#x4E2D;&#x5FC3;&#x70B9;</li>
<li>&#x5982;&#x679C;&#x4E2D;&#x5FC3;&#x70B9;&#x4E0D;&#x5728;Polygon&#x5185;&#x90E8;&#xFF0C;&#x5219;&#x8FD4;&#x56DE;&#x4E0E;&#x4E2D;&#x5FC3;&#x70B9;&#x6700;&#x63A5;&#x8FD1;&#x7684;&#x70B9;</li>
</ol>
<p>&#x4E0B;&#x9762;&#x9010;&#x6B65;&#x770B;&#x5B9E;&#x73B0;&#x8FC7;&#x7A0B;</p>
<ol>
<li>&#x53C2;&#x8003;centerid&#x7684;&#x83B7;&#x53D6;&#x8FC7;&#x7A0B;</li>
<li>&#x5224;&#x65AD;&#x4E2D;&#x5FC3;&#x70B9;&#x662F;&#x5426;&#x5728;Polygon&#x5185;&#x90E8;, &#x53C2;&#x8003;&#x3010;booleanPointInPolygon&#x3011;&#x65B9;&#x6CD5;</li>
<li>&#x5982;&#x679C;centerid&#x5728;Polygon&#x5185;&#x90E8;&#xFF0C;&#x5219;&#x8FD4;&#x56DE;centerid</li>
<li>&#x5982;&#x679C;centerid&#x4E0D;&#x5728;Polygon&#x5185;&#x90E8;&#xFF0C;&#x5219;&#x8FD4;&#x56DE;Polygon&#x4E0E;centerid&#x6700;&#x63A5;&#x8FD1;&#x7684;&#x70B9;&#xFF0C;&#x53C2;&#x8003;&#x3010;nearestPoint&#x3011;&#x65B9;&#x6CD5;</li>
</ol>
<h1 id="polygontangents">polygonTangents</h1>
<p>&#x83B7;&#x53D6;&#x591A;&#x8FB9;&#x5F62;&#x76F8;&#x5BF9;&#x4E8E;&#x591A;&#x8FB9;&#x5F62;&#x5916;&#x7684;&#x70B9;&#x7684;&#x5207;&#x70B9;&#x96C6;&#x5408;</p>
<h1 id="pointtolinedistance">pointToLineDistance</h1>
<p>&#x83B7;&#x53D6;&#x70B9;&#x5230;&#x7EBF;&#x7684;&#x8DDD;&#x79BB;&#xFF0C;&#x8FD9;&#x91CC;&#x7684;&#x7EBF;&#x6307;&#x7684;&#x662F;&#x5177;&#x6709;&#x7EBF;&#x7ED3;&#x6784;&#x7684;feature,&#x53EF;&#x4EE5;&#x662F;LineString&#x4E5F;&#x53EF;&#x4EE5;&#x662F;Polygon&#x3002;&#x8FD9;&#x91CC;&#x4E00;&#x6761;&#x6298;&#x7EBF;&#x6BB5;&#x8003;&#x8651;&#xFF0C;&#x83B7;&#x53D6;&#x6298;&#x7EBF;&#x6BB5;&#x5916;&#x4E00;&#x70B9;A&#x5230;&#x8FD9;&#x6761;&#x6298;&#x7EBF;&#x6BB5;L&#x7684;&#x6700;&#x77ED;&#x8DDD;&#x79BB;&#x3002;</p>
<p>&#x601D;&#x8DEF;&#xFF1A;&#x83B7;&#x53D6;&#x6298;&#x7EBF;&#x6BB5;&#x7684;&#x6700;&#x77ED;&#x8DDD;&#x79BB;&#xFF0C;&#x53EF;&#x4EE5;&#x6BD4;&#x8F83;&#x70B9;A&#x4E0E;L&#x4E0A;&#x5404;&#x4E2A;&#x7EBF;&#x6BB5;&#x7684;&#x8DDD;&#x79BB;&#xFF0C;&#x53D6;&#x6700;&#x5C0F;&#x7684;&#x503C;&#x5373;&#x53EF;&#x3002;&#x5982;&#x4F55;&#x83B7;&#x53D6;&#x70B9;&#x5230;&#x7EBF;&#x6BB5;&#x7684;&#x8DDD;&#x79BB;&#x5462;&#xFF1F;&#x6211;&#x4EEC;&#x5148;&#x770B;&#x770B;&#x70B9;&#x5728;&#x7EBF;&#x6BB5;&#x5916;&#x7684;&#x4E09;&#x79CD;&#x60C5;&#x51B5;&#xFF1A;
<img src="../Image/Snipaste_2020-06-18_16-08-19.png" alt=""></p>
<ul>
<li>&#x7B2C;&#x4E00;&#x79CD;&#x60C5;&#x51B5;G&#x70B9;&#x5230;&#x7EBF;AB&#x7684;&#x6700;&#x77ED;&#x8DDD;&#x79BB;&#x4E3A;AG, &#x5939;&#x89D2;&#x533A;&#x95F4;[90 180]</li>
<li>&#x7B2C;&#x4E8C;&#x79CD;&#x60C5;&#x51B5;H&#x70B9;&#x5230;&#x7EBF;CD&#x7684;&#x6700;&#x77ED;&#x8DDD;&#x79BB;&#x4E3A;DH, &#x5939;&#x89D2;&#x533A;&#x95F4;[0 90)</li>
<li>&#x7B2C;&#x4E09;&#x79CD;&#x60C5;&#x51B5;I&#x70B9;&#x5230;&#x7EBF;EF&#x7684;&#x6700;&#x77ED;&#x8DDD;&#x79BB;&#x4E3A;I&#x70B9;&#x5230;&#x7EBF;EF&#x7684;&#x5782;&#x7EBF;&#xFF0C;&#x5939;&#x89D2;&#x533A;&#x95F4;&#x4E3A;[0, 90)</li>
</ul>
<p>&#x89E3;&#x51B3;&#x8FD9;&#x4E2A;&#x6700;&#x77ED;&#x8DDD;&#x79BB;&#x7684;&#x95EE;&#x9898;&#x6709;&#x4E24;&#x79CD;&#xFF1A;1&#xFF09;&#x89E3;&#x6790;&#x51E0;&#x4F55;   2&#xFF09; &#x5411;&#x91CF;</p>
<p>&#x901A;&#x8FC7;&#x89E3;&#x6790;&#x51E0;&#x4F55;&#x7684;&#x65B9;&#x6CD5;&#x8F83;&#x4E3A;&#x7E41;&#x7410;&#xFF0C;&#x800C;&#x4E14;&#x7A0B;&#x5E8F;&#x8FD0;&#x884C;&#x7684;&#x5F00;&#x9500;&#x8F83;&#x5927;&#xFF0C;&#x8FD9;&#x91CC;&#x7528;&#x5411;&#x91CF;&#x89E3;&#x51B3;, G&#xFF08;x, y&#xFF09;&#xFF0C;A(x1,  y1)&#xFF0C;B(x2, y2)&#x4E09;&#x70B9;&#x5750;&#x6807;&#x5DF2;&#x77E5;&#x3002;</p>
<p>&#x7B2C;&#x4E00;&#x79CD;&#x60C5;&#x51B5;:</p>
<p>AB&#x5411;&#x91CF;&#x4E0E;AG&#x5411;&#x91CF;&#x7684;&#x6570;&#x4E58;&#x4E0D;&#x5927;&#x4E8E;0</p>
<p>(x - x1) <em> (x2 - x1) + (y - y1)</em>(y2 - y1) &lt;= 0;</p>
<p>&#x7B2C;&#x4E8C;&#x79CD;&#x60C5;&#x51B5;&#xFF1A;</p>
<p>AB&#x5411;&#x91CF;&#x4E0E;AG&#x5411;&#x91CF;&#x7684;&#x6570;&#x4E58;&#x4E0D;&#x5C0F;&#x4E8E;AB&#x5411;&#x91CF;&#x7684;&#x81EA;&#x4E58;&#xFF0C;&#x63A8;&#x5BFC;&#x4E0D;&#x96BE;</p>
<p>(x - x1) <em> (x2 - x1) + (y - y1)</em>(y2 - y1 &gt;= (x2 - x1)(x2 - x1) + (y2 - y1)(y2 - y1)</p>
<p>&#x7B2C;&#x4E09;&#x79CD;&#x60C5;&#x51B5;&#xFF1A;</p>
<p>&#x9664;&#x4E86;&#x7B2C;&#x4E00;&#x3001;&#x4E8C;&#x79CD;&#x60C5;&#x51B5;&#x5373;&#x4E3A;&#x7B2C;&#x4E09;&#x79CD;&#x60C5;&#x51B5;</p>
<p>&#x5782;&#x7EBF;&#x7684;&#x957F;&#x5EA6;&#x53EF;&#x901A;&#x8FC7;&#x89E3;&#x6790;&#x51E0;&#x4F55;&#x8BA1;&#x7B97;&#xFF0C;&#x4E5F;&#x53EF;&#x901A;&#x8FC7;&#x5411;&#x91CF;&#x8BA1;&#x7B97;</p>
<h1 id="rhumbbearing">rhumbBearing</h1>
<blockquote>
<p>&#x7406;&#x89E3;&#x6052;&#x5411;&#x89D2;&#x4E4B;&#x524D;&#x9700;&#x8981;&#x5148;&#x4E86;&#x89E3;&#x5927;&#x5706;&#x822A;&#x7EBF;&#x548C;&#x6052;&#x5411;&#x822A;&#x7EBF;&#xFF0C;&#x5927;&#x5706;&#x822A;&#x7EBF;&#x662F;&#x4E24;&#x70B9;&#x4E4B;&#x95F4;&#x8DDD;&#x79BB;&#x6700;&#x8FD1;&#x7684;&#x822A;&#x7EBF;&#xFF0C;&#x4F46;&#x662F;&#x4E00;&#x822C;&#x60C5;&#x51B5;&#x4E0B;&#x822A;&#x7EBF;&#x4E0E;&#x7ECF;&#x7EBF;&#x89D2;&#x5EA6;&#x662F;&#x4E0D;&#x65AD;&#x53D8;&#x5316;&#x7684;&#xFF08;&#x7ECF;&#x7EBF;&#x5708;&#x548C;&#x7EAC;&#x7EBF;&#x5708;&#x9664;&#x5916;&#xFF09;&#xFF0C;&#x8FD9;&#x5C31;&#x610F;&#x5473;&#x7740;&#x5982;&#x679C;&#x7528;&#x7F57;&#x76D8;&#x5BFC;&#x822A;&#x7684;&#x8BDD;&#xFF08;&#x7F57;&#x76D8;&#x5317;&#x65B9;&#x5411;&#x4E0E;&#x7ECF;&#x7EBF;&#x8FD1;&#x4F3C;&#x4E00;&#x81F4;&#xFF09;&#x5C31;&#x9700;&#x8981;&#x4E0D;&#x505C;&#x5730;&#x53D8;&#x6362;&#x822A;&#x5411;&#x3002;&#x6052;&#x5411;&#x822A;&#x7EBF;&#x91CC;&#x9762;&#x7684;&#x8FD9;&#x4E2A;&#x6052;&#x5411;&#x6307;&#x7684;&#x662F;&#x7F57;&#x76D8;&#x4E0A;&#x7684;&#x6307;&#x9488;&#x662F;&#x4E0D;&#x53D8;&#x7684;&#xFF0C;&#x4E5F;&#x5C31;&#x662F;&#x8BF4;&#x822A;&#x7EBF;&#x4E0E;&#x7ECF;&#x7EBF;&#x7684;&#x5939;&#x89D2;&#x4E00;&#x81F4;&#x3002;&#x5176;&#x5B9E;&#x6052;&#x5411;&#x822A;&#x7EBF;&#x5176;&#x5B9E;&#x662F;&#x4E00;&#x6761;&#x66F2;&#x7EBF;&#xFF0C;&#x800C;&#x5927;&#x5706;&#x822A;&#x7EBF;&#x53EF;&#x4EE5;&#x770B;&#x505A;&#x4E00;&#x6761;&#x76F4;&#x7EBF;&#xFF0C;&#x6709;&#x8FD9;&#x4E2A;&#x533A;&#x5206;&#x662F;&#x6307;&#x7528;&#x7F57;&#x76D8;&#x6765;&#x5BFC;&#x822A;&#x6765;&#x8BF4;&#x7684;&#xFF0C;&#x5982;&#x679C;&#x73B0;&#x4EE3;&#x7684;GPS&#x5B9A;&#x4F4D;&#x5C31;&#x53EA;&#x9700;&#x8981;&#x7528;&#x5927;&#x5706;&#x822A;&#x7EBF;&#x8FD9;&#x6761;&#x6700;&#x77ED;&#x8DEF;&#x7EBF;&#x4E86;&#x3002;</p>
</blockquote>
<p>&#x83B7;&#x53D6;&#x6052;&#x5411;&#x89D2;&#xFF0C;&#x5373;&#x662F;&#x6052;&#x5411;&#x822A;&#x7EBF;&#x65F6;&#x822A;&#x7EBF;&#x4E0E;&#x7ECF;&#x5EA6;&#x7684;&#x5939;&#x89D2;&#x3002;</p>
<p>// TODO: &#x5F85;&#x5B8C;&#x5584;</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">calculateRhumbBearing</span>(<span class="hljs-params">from: number[], to: number[]</span>) </span>{
    <span class="hljs-comment">// &#x3C6; =&gt; phi</span>
    <span class="hljs-comment">// &#x394;&#x3BB; =&gt; deltaLambda</span>
    <span class="hljs-comment">// &#x394;&#x3C8; =&gt; deltaPsi</span>
    <span class="hljs-comment">// &#x3B8; =&gt; theta</span>
    <span class="hljs-keyword">const</span> phi1 = degreesToRadians(<span class="hljs-keyword">from</span>[<span class="hljs-number">1</span>]);
    <span class="hljs-keyword">const</span> phi2 = degreesToRadians(to[<span class="hljs-number">1</span>]);
    <span class="hljs-keyword">let</span> deltaLambda = degreesToRadians((to[<span class="hljs-number">0</span>] - <span class="hljs-keyword">from</span>[<span class="hljs-number">0</span>]));
    <span class="hljs-comment">// if deltaLambdaon over 180&#xB0; take shorter rhumb line across the anti-meridian:</span>
    <span class="hljs-keyword">if</span> (deltaLambda &gt; <span class="hljs-built_in">Math</span>.PI) { deltaLambda -= <span class="hljs-number">2</span> * <span class="hljs-built_in">Math</span>.PI; }
    <span class="hljs-keyword">if</span> (deltaLambda &lt; -<span class="hljs-built_in">Math</span>.PI) { deltaLambda += <span class="hljs-number">2</span> * <span class="hljs-built_in">Math</span>.PI; }

    <span class="hljs-keyword">const</span> deltaPsi = <span class="hljs-built_in">Math</span>.log(<span class="hljs-built_in">Math</span>.tan(phi2 / <span class="hljs-number">2</span> + <span class="hljs-built_in">Math</span>.PI / <span class="hljs-number">4</span>) / <span class="hljs-built_in">Math</span>.tan(phi1 / <span class="hljs-number">2</span> + <span class="hljs-built_in">Math</span>.PI / <span class="hljs-number">4</span>));

    <span class="hljs-keyword">const</span> theta = <span class="hljs-built_in">Math</span>.atan2(deltaLambda, deltaPsi);

    <span class="hljs-keyword">return</span> (radiansToDegrees(theta) + <span class="hljs-number">360</span>) % <span class="hljs-number">360</span>;
}
</code></pre>
<h1 id="rhumbdestination">rhumbDestination</h1>
<p>&#x7ED9;&#x5B9A;&#x4E00;&#x4E2A;&#x70B9;&#x548C;&#x8DDD;&#x79BB;&#x548C;&#x7F57;&#x76D8;&#x65B9;&#x4F4D;&#x89D2;&#xFF0C;&#x6C42;&#x53E6;&#x4E00;&#x4E2A;&#x70B9;</p>
<p>// TODO:&#x5F85;&#x5B8C;&#x5584;</p>
<pre><code class="lang-javascript"><span class="hljs-comment">/**
 * Returns the destination point having travelled along a rhumb line from origin point the given
 * distance on the  given bearing.
 * Adapted from Geodesy: http://www.movable-type.co.uk/scripts/latlong.html#rhumblines
 *
 * @private
 * @param   {Array&lt;number&gt;} origin - point
 * @param   {number} distance - Distance travelled, in same units as earth radius (default: metres).
 * @param   {number} bearing - Bearing in degrees from north.
 * @param   {number} [radius=6371e3] - (Mean) radius of earth (defaults to radius in metres).
 * @returns {Array&lt;number&gt;} Destination point.
 */</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">calculateRhumbDestination</span>(<span class="hljs-params">origin: number[], distance: number, bearing: number, radius?: number</span>) </span>{
    <span class="hljs-comment">// &#x3C6; =&gt; phi</span>
    <span class="hljs-comment">// &#x3BB; =&gt; lambda</span>
    <span class="hljs-comment">// &#x3C8; =&gt; psi</span>
    <span class="hljs-comment">// &#x394; =&gt; Delta</span>
    <span class="hljs-comment">// &#x3B4; =&gt; delta</span>
    <span class="hljs-comment">// &#x3B8; =&gt; theta</span>

    radius = (radius === <span class="hljs-literal">undefined</span>) ? earthRadius : <span class="hljs-built_in">Number</span>(radius);

    <span class="hljs-keyword">const</span> delta = distance / radius; <span class="hljs-comment">// angular distance in radians</span>
    <span class="hljs-keyword">const</span> lambda1 = origin[<span class="hljs-number">0</span>] * <span class="hljs-built_in">Math</span>.PI / <span class="hljs-number">180</span>; <span class="hljs-comment">// to radians, but without normalize to &#x1D70B;</span>
    <span class="hljs-keyword">const</span> phi1 = degreesToRadians(origin[<span class="hljs-number">1</span>]);
    <span class="hljs-keyword">const</span> theta = degreesToRadians(bearing);

    <span class="hljs-keyword">const</span> DeltaPhi = delta * <span class="hljs-built_in">Math</span>.cos(theta);
    <span class="hljs-keyword">let</span> phi2 = phi1 + DeltaPhi;

    <span class="hljs-comment">// check for some daft bugger going past the pole, normalise latitude if so</span>
    <span class="hljs-keyword">if</span> (<span class="hljs-built_in">Math</span>.abs(phi2) &gt; <span class="hljs-built_in">Math</span>.PI / <span class="hljs-number">2</span>) { phi2 = phi2 &gt; <span class="hljs-number">0</span> ? <span class="hljs-built_in">Math</span>.PI - phi2 : -<span class="hljs-built_in">Math</span>.PI - phi2; }

    <span class="hljs-keyword">const</span> DeltaPsi = <span class="hljs-built_in">Math</span>.log(<span class="hljs-built_in">Math</span>.tan(phi2 / <span class="hljs-number">2</span> + <span class="hljs-built_in">Math</span>.PI / <span class="hljs-number">4</span>) / <span class="hljs-built_in">Math</span>.tan(phi1 / <span class="hljs-number">2</span> + <span class="hljs-built_in">Math</span>.PI / <span class="hljs-number">4</span>));
    <span class="hljs-comment">// E-W course becomes ill-conditioned with 0/0</span>
    <span class="hljs-keyword">const</span> q = <span class="hljs-built_in">Math</span>.abs(DeltaPsi) &gt; <span class="hljs-number">10e-12</span> ? DeltaPhi / DeltaPsi : <span class="hljs-built_in">Math</span>.cos(phi1);

    <span class="hljs-keyword">const</span> DeltaLambda = delta * <span class="hljs-built_in">Math</span>.sin(theta) / q;
    <span class="hljs-keyword">const</span> lambda2 = lambda1 + DeltaLambda;

    <span class="hljs-keyword">return</span> [((lambda2 * <span class="hljs-number">180</span> / <span class="hljs-built_in">Math</span>.PI) + <span class="hljs-number">540</span>) % <span class="hljs-number">360</span> - <span class="hljs-number">180</span>, phi2 * <span class="hljs-number">180</span> / <span class="hljs-built_in">Math</span>.PI]; <span class="hljs-comment">// normalise to &#x2212;180..+180&#xB0;</span>
}
</code></pre>
<h1 id="rhumbdistance">rhumbDistance</h1>
<p>&#x83B7;&#x53D6;&#x7F57;&#x76D8;&#x65B9;&#x4F4D;&#x8DDD;&#x79BB;</p>
<p>// TODO: &#x5F85;&#x5B8C;&#x5584;</p>
<pre><code class="lang-javascript"><span class="hljs-comment">/**
 * Returns the distance travelling from &#x2018;this&#x2019; point to destination point along a rhumb line.
 * Adapted from Geodesy: https://github.com/chrisveness/geodesy/blob/master/latlon-spherical.js
 *
 * @private
 * @param   {Array&lt;number&gt;} origin point.
 * @param   {Array&lt;number&gt;} destination point.
 * @param   {number} [radius=6371e3] - (Mean) radius of earth (defaults to radius in metres).
 * @returns {number} Distance in km between this point and destination point (same units as radius).
 *
 * @example
 *     var p1 = new LatLon(51.127, 1.338);
 *     var p2 = new LatLon(50.964, 1.853);
 *     var d = p1.distanceTo(p2); // 40.31 km
 */</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">calculateRhumbDistance</span>(<span class="hljs-params">origin: number[], destination: number[], radius?: number</span>) </span>{
    <span class="hljs-comment">// &#x3C6; =&gt; phi</span>
    <span class="hljs-comment">// &#x3BB; =&gt; lambda</span>
    <span class="hljs-comment">// &#x3C8; =&gt; psi</span>
    <span class="hljs-comment">// &#x394; =&gt; Delta</span>
    <span class="hljs-comment">// &#x3B4; =&gt; delta</span>
    <span class="hljs-comment">// &#x3B8; =&gt; theta</span>

    radius = (radius === <span class="hljs-literal">undefined</span>) ? earthRadius : <span class="hljs-built_in">Number</span>(radius);
    <span class="hljs-comment">// see www.edwilliams.org/avform.htm#Rhumb</span>

    <span class="hljs-keyword">const</span> R = radius;
    <span class="hljs-keyword">const</span> phi1 = origin[<span class="hljs-number">1</span>] * <span class="hljs-built_in">Math</span>.PI / <span class="hljs-number">180</span>;
    <span class="hljs-keyword">const</span> phi2 = destination[<span class="hljs-number">1</span>] * <span class="hljs-built_in">Math</span>.PI / <span class="hljs-number">180</span>;
    <span class="hljs-keyword">const</span> DeltaPhi = phi2 - phi1;
    <span class="hljs-keyword">let</span> DeltaLambda = <span class="hljs-built_in">Math</span>.abs(destination[<span class="hljs-number">0</span>] - origin[<span class="hljs-number">0</span>]) * <span class="hljs-built_in">Math</span>.PI / <span class="hljs-number">180</span>;
    <span class="hljs-comment">// if dLon over 180&#xB0; take shorter rhumb line across the anti-meridian:</span>
    <span class="hljs-keyword">if</span> (DeltaLambda &gt; <span class="hljs-built_in">Math</span>.PI) { DeltaLambda -= <span class="hljs-number">2</span> * <span class="hljs-built_in">Math</span>.PI; }

    <span class="hljs-comment">// on Mercator projection, longitude distances shrink by latitude; q is the &apos;stretch factor&apos;</span>
    <span class="hljs-comment">// q becomes ill-conditioned along E-W line (0/0); use empirical tolerance to avoid it</span>
    <span class="hljs-keyword">const</span> DeltaPsi = <span class="hljs-built_in">Math</span>.log(<span class="hljs-built_in">Math</span>.tan(phi2 / <span class="hljs-number">2</span> + <span class="hljs-built_in">Math</span>.PI / <span class="hljs-number">4</span>) / <span class="hljs-built_in">Math</span>.tan(phi1 / <span class="hljs-number">2</span> + <span class="hljs-built_in">Math</span>.PI / <span class="hljs-number">4</span>));
    <span class="hljs-keyword">const</span> q = <span class="hljs-built_in">Math</span>.abs(DeltaPsi) &gt; <span class="hljs-number">10e-12</span> ? DeltaPhi / DeltaPsi : <span class="hljs-built_in">Math</span>.cos(phi1);

    <span class="hljs-comment">// distance is pythagoras on &apos;stretched&apos; Mercator projection</span>
    <span class="hljs-keyword">const</span> delta = <span class="hljs-built_in">Math</span>.sqrt(DeltaPhi * DeltaPhi + q * q * DeltaLambda * DeltaLambda); <span class="hljs-comment">// angular distance in radians</span>
    <span class="hljs-keyword">const</span> dist = delta * R;

    <span class="hljs-keyword">return</span> dist;
}
</code></pre>
<h1 id="square">square</h1>
<p>&#x83B7;&#x53D6;&#x5305;&#x542B;&#x5757;&#x7684;&#x6700;&#x5C0F;&#x6B63;&#x65B9;&#x5F62;&#x5305;&#x542B;&#x5757;</p>
<p><strong>&#x601D;&#x8DEF;&#xFF1A;</strong></p>
<p>1&#x3001;&#x5224;&#x65AD;&#x5305;&#x542B;&#x5757;&#x662F;&#x7AD6;&#x76F4;&#x8FD8;&#x662F;&#x6C34;&#x5E73;&#x7684;</p>
<p>2&#x3001;&#x5305;&#x542B;&#x5757;&#x662F;&#x7AD6;&#x76F4;&#x7684;&#x5219;&#x4ECE;&#x4E2D;&#x5FC3;&#x5EF6;&#x4F38;&#x6C34;&#x5E73;&#x4F4D;&#x7F6E;&#xFF0C;&#x5EF6;&#x4F38;&#x5230;&#x7AD6;&#x76F4;&#x957F;&#x5EA6;&#x7684;&#x4E00;&#x534A;</p>
<p>3&#x3001;&#x5305;&#x542B;&#x5757;&#x662F;&#x6C34;&#x5E73;&#x7684;&#x5219;&#x4ECE;&#x4E2D;&#x5FC3;&#x5EF6;&#x4F38;&#x7AD6;&#x76F4;&#x4F4D;&#x7F6E;&#xFF0C;&#x5EF6;&#x4F38;&#x5230;&#x6C34;&#x5E73;&#x957F;&#x5EA6;&#x7684;&#x4E00;&#x534A;</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">square</span>(<span class="hljs-params">bbox</span>) </span>{
    <span class="hljs-keyword">var</span> west = bbox[<span class="hljs-number">0</span>];
    <span class="hljs-keyword">var</span> south = bbox[<span class="hljs-number">1</span>];
    <span class="hljs-keyword">var</span> east = bbox[<span class="hljs-number">2</span>];
    <span class="hljs-keyword">var</span> north = bbox[<span class="hljs-number">3</span>];

    <span class="hljs-keyword">var</span> horizontalDistance = distance(bbox.slice(<span class="hljs-number">0</span>, <span class="hljs-number">2</span>), [east, south]);
    <span class="hljs-keyword">var</span> verticalDistance = distance(bbox.slice(<span class="hljs-number">0</span>, <span class="hljs-number">2</span>), [west, north]);
    <span class="hljs-comment">// &#x6C34;&#x5E73;&#x6446;&#x653E;</span>
    <span class="hljs-keyword">if</span> (horizontalDistance &gt;= verticalDistance) {
        <span class="hljs-keyword">var</span> verticalMidpoint = (south + north) / <span class="hljs-number">2</span>;
        <span class="hljs-keyword">return</span> [
            west,
            verticalMidpoint - ((east - west) / <span class="hljs-number">2</span>),
            east,
            verticalMidpoint + ((east - west) / <span class="hljs-number">2</span>)
        ];
    } 
    <span class="hljs-comment">// &#x7AD6;&#x76F4;&#x6446;&#x653E;</span>
    <span class="hljs-keyword">else</span> {
        <span class="hljs-keyword">var</span> horizontalMidpoint = (west + east) / <span class="hljs-number">2</span>;
        <span class="hljs-keyword">return</span> [
            horizontalMidpoint - ((north - south) / <span class="hljs-number">2</span>),
            south,
            horizontalMidpoint + ((north - south) / <span class="hljs-number">2</span>),
            north
        ];
    }
}
</code></pre>
<h1 id="greatcircle">greatCircle</h1>
<p>&#x8FD4;&#x56DE;&#x4E24;&#x70B9;&#x95F4;&#x7684;&#x5927;&#x5706;&#x8DEF;&#x5F84;</p>
<p>// TODO: &#x5F85;&#x5B8C;&#x6210;</p>
<pre><code class="lang-javascript"><span class="hljs-comment">/*
 * http://en.wikipedia.org/wiki/Great-circle_distance
 *
 */</span>
<span class="hljs-keyword">var</span> GreatCircle = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">start, end, properties</span>) </span>{
    <span class="hljs-keyword">if</span> (!start || start.x === <span class="hljs-literal">undefined</span> || start.y === <span class="hljs-literal">undefined</span>) {
        <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Error</span>(<span class="hljs-string">&apos;GreatCircle constructor expects two args: start and end objects with x and y properties&apos;</span>);
    }
    <span class="hljs-keyword">if</span> (!end || end.x === <span class="hljs-literal">undefined</span> || end.y === <span class="hljs-literal">undefined</span>) {
        <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Error</span>(<span class="hljs-string">&apos;GreatCircle constructor expects two args: start and end objects with x and y properties&apos;</span>);
    }
    <span class="hljs-keyword">this</span>.start = <span class="hljs-keyword">new</span> Coord(start.x, start.y);
    <span class="hljs-keyword">this</span>.end = <span class="hljs-keyword">new</span> Coord(end.x, end.y);
    <span class="hljs-keyword">this</span>.properties = properties || {};

    <span class="hljs-keyword">var</span> w = <span class="hljs-keyword">this</span>.start.x - <span class="hljs-keyword">this</span>.end.x;
    <span class="hljs-keyword">var</span> h = <span class="hljs-keyword">this</span>.start.y - <span class="hljs-keyword">this</span>.end.y;
    <span class="hljs-keyword">var</span> z = <span class="hljs-built_in">Math</span>.pow(<span class="hljs-built_in">Math</span>.sin(h / <span class="hljs-number">2.0</span>), <span class="hljs-number">2</span>) +
                <span class="hljs-built_in">Math</span>.cos(<span class="hljs-keyword">this</span>.start.y) *
                   <span class="hljs-built_in">Math</span>.cos(<span class="hljs-keyword">this</span>.end.y) *
                     <span class="hljs-built_in">Math</span>.pow(<span class="hljs-built_in">Math</span>.sin(w / <span class="hljs-number">2.0</span>), <span class="hljs-number">2</span>);
    <span class="hljs-keyword">this</span>.g = <span class="hljs-number">2.0</span> * <span class="hljs-built_in">Math</span>.asin(<span class="hljs-built_in">Math</span>.sqrt(z));

    <span class="hljs-keyword">if</span> (<span class="hljs-keyword">this</span>.g === <span class="hljs-built_in">Math</span>.PI) {
        <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Error</span>(<span class="hljs-string">&apos;it appears &apos;</span> + start.view() + <span class="hljs-string">&apos; and &apos;</span> + end.view() + <span class="hljs-string">&apos; are \&apos;antipodal\&apos;, e.g diametrically opposite, thus there is no single route but rather infinite&apos;</span>);
    } <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (<span class="hljs-built_in">isNaN</span>(<span class="hljs-keyword">this</span>.g)) {
        <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Error</span>(<span class="hljs-string">&apos;could not calculate great circle between &apos;</span> + start + <span class="hljs-string">&apos; and &apos;</span> + end);
    }
};

<span class="hljs-comment">/*
 * Generate points along the great circle
 */</span>
GreatCircle.prototype.Arc = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">npoints, options</span>) </span>{
    <span class="hljs-keyword">var</span> first_pass = [];
    <span class="hljs-keyword">if</span> (!npoints || npoints &lt;= <span class="hljs-number">2</span>) {
        first_pass.push([<span class="hljs-keyword">this</span>.start.lon, <span class="hljs-keyword">this</span>.start.lat]);
        first_pass.push([<span class="hljs-keyword">this</span>.end.lon, <span class="hljs-keyword">this</span>.end.lat]);
    } <span class="hljs-keyword">else</span> {
        <span class="hljs-keyword">var</span> delta = <span class="hljs-number">1.0</span> / (npoints - <span class="hljs-number">1</span>);
        <span class="hljs-keyword">for</span> (<span class="hljs-keyword">var</span> i = <span class="hljs-number">0</span>; i &lt; npoints; ++i) {
            <span class="hljs-keyword">var</span> step = delta * i;
            <span class="hljs-keyword">var</span> pair = <span class="hljs-keyword">this</span>.interpolate(step);
            first_pass.push(pair);
        }
    }
    <span class="hljs-comment">/* partial port of dateline handling from:
      gdal/ogr/ogrgeometryfactory.cpp

      TODO - does not handle all wrapping scenarios yet
    */</span>
    <span class="hljs-keyword">var</span> bHasBigDiff = <span class="hljs-literal">false</span>;
    <span class="hljs-keyword">var</span> dfMaxSmallDiffLong = <span class="hljs-number">0</span>;
    <span class="hljs-comment">// from http://www.gdal.org/ogr2ogr.html</span>
    <span class="hljs-comment">// -datelineoffset:</span>
    <span class="hljs-comment">// (starting with GDAL 1.10) offset from dateline in degrees (default long. = +/- 10deg, geometries within 170deg to -170deg will be splited)</span>
    <span class="hljs-keyword">var</span> dfDateLineOffset = options &amp;&amp; options.offset ? options.offset : <span class="hljs-number">10</span>;
    <span class="hljs-keyword">var</span> dfLeftBorderX = <span class="hljs-number">180</span> - dfDateLineOffset;
    <span class="hljs-keyword">var</span> dfRightBorderX = <span class="hljs-number">-180</span> + dfDateLineOffset;
    <span class="hljs-keyword">var</span> dfDiffSpace = <span class="hljs-number">360</span> - dfDateLineOffset;

    <span class="hljs-comment">// https://github.com/OSGeo/gdal/blob/7bfb9c452a59aac958bff0c8386b891edf8154ca/gdal/ogr/ogrgeometryfactory.cpp#L2342</span>
    <span class="hljs-keyword">for</span> (<span class="hljs-keyword">var</span> j = <span class="hljs-number">1</span>; j &lt; first_pass.length; ++j) {
        <span class="hljs-keyword">var</span> dfPrevX = first_pass[j - <span class="hljs-number">1</span>][<span class="hljs-number">0</span>];
        <span class="hljs-keyword">var</span> dfX = first_pass[j][<span class="hljs-number">0</span>];
        <span class="hljs-keyword">var</span> dfDiffLong = <span class="hljs-built_in">Math</span>.abs(dfX - dfPrevX);
        <span class="hljs-keyword">if</span> (dfDiffLong &gt; dfDiffSpace &amp;&amp;
            ((dfX &gt; dfLeftBorderX &amp;&amp; dfPrevX &lt; dfRightBorderX) || (dfPrevX &gt; dfLeftBorderX &amp;&amp; dfX &lt; dfRightBorderX))) {
            bHasBigDiff = <span class="hljs-literal">true</span>;
        } <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (dfDiffLong &gt; dfMaxSmallDiffLong) {
            dfMaxSmallDiffLong = dfDiffLong;
        }
    }

    <span class="hljs-keyword">var</span> poMulti = [];
    <span class="hljs-keyword">if</span> (bHasBigDiff &amp;&amp; dfMaxSmallDiffLong &lt; dfDateLineOffset) {
        <span class="hljs-keyword">var</span> poNewLS = [];
        poMulti.push(poNewLS);
        <span class="hljs-keyword">for</span> (<span class="hljs-keyword">var</span> k = <span class="hljs-number">0</span>; k &lt; first_pass.length; ++k) {
            <span class="hljs-keyword">var</span> dfX0 = <span class="hljs-built_in">parseFloat</span>(first_pass[k][<span class="hljs-number">0</span>]);
            <span class="hljs-keyword">if</span> (k &gt; <span class="hljs-number">0</span> &amp;&amp;  <span class="hljs-built_in">Math</span>.abs(dfX0 - first_pass[k - <span class="hljs-number">1</span>][<span class="hljs-number">0</span>]) &gt; dfDiffSpace) {
                <span class="hljs-keyword">var</span> dfX1 = <span class="hljs-built_in">parseFloat</span>(first_pass[k - <span class="hljs-number">1</span>][<span class="hljs-number">0</span>]);
                <span class="hljs-keyword">var</span> dfY1 = <span class="hljs-built_in">parseFloat</span>(first_pass[k - <span class="hljs-number">1</span>][<span class="hljs-number">1</span>]);
                <span class="hljs-keyword">var</span> dfX2 = <span class="hljs-built_in">parseFloat</span>(first_pass[k][<span class="hljs-number">0</span>]);
                <span class="hljs-keyword">var</span> dfY2 = <span class="hljs-built_in">parseFloat</span>(first_pass[k][<span class="hljs-number">1</span>]);
                <span class="hljs-keyword">if</span> (dfX1 &gt; <span class="hljs-number">-180</span> &amp;&amp; dfX1 &lt; dfRightBorderX &amp;&amp; dfX2 === <span class="hljs-number">180</span> &amp;&amp;
                    k + <span class="hljs-number">1</span> &lt; first_pass.length &amp;&amp;
                   first_pass[k - <span class="hljs-number">1</span>][<span class="hljs-number">0</span>] &gt; <span class="hljs-number">-180</span> &amp;&amp; first_pass[k - <span class="hljs-number">1</span>][<span class="hljs-number">0</span>] &lt; dfRightBorderX) {
                    poNewLS.push([<span class="hljs-number">-180</span>, first_pass[k][<span class="hljs-number">1</span>]]);
                    k++;
                    poNewLS.push([first_pass[k][<span class="hljs-number">0</span>], first_pass[k][<span class="hljs-number">1</span>]]);
                    <span class="hljs-keyword">continue</span>;
                } <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (dfX1 &gt; dfLeftBorderX &amp;&amp; dfX1 &lt; <span class="hljs-number">180</span> &amp;&amp; dfX2 === <span class="hljs-number">-180</span> &amp;&amp;
                     k + <span class="hljs-number">1</span> &lt; first_pass.length &amp;&amp;
                     first_pass[k - <span class="hljs-number">1</span>][<span class="hljs-number">0</span>] &gt; dfLeftBorderX &amp;&amp; first_pass[k - <span class="hljs-number">1</span>][<span class="hljs-number">0</span>] &lt; <span class="hljs-number">180</span>) {
                    poNewLS.push([<span class="hljs-number">180</span>, first_pass[k][<span class="hljs-number">1</span>]]);
                    k++;
                    poNewLS.push([first_pass[k][<span class="hljs-number">0</span>], first_pass[k][<span class="hljs-number">1</span>]]);
                    <span class="hljs-keyword">continue</span>;
                }

                <span class="hljs-keyword">if</span> (dfX1 &lt; dfRightBorderX &amp;&amp; dfX2 &gt; dfLeftBorderX) {
                    <span class="hljs-comment">// swap dfX1, dfX2</span>
                    <span class="hljs-keyword">var</span> tmpX = dfX1;
                    dfX1 = dfX2;
                    dfX2 = tmpX;
                    <span class="hljs-comment">// swap dfY1, dfY2</span>
                    <span class="hljs-keyword">var</span> tmpY = dfY1;
                    dfY1 = dfY2;
                    dfY2 = tmpY;
                }
                <span class="hljs-keyword">if</span> (dfX1 &gt; dfLeftBorderX &amp;&amp; dfX2 &lt; dfRightBorderX) {
                    dfX2 += <span class="hljs-number">360</span>;
                }

                <span class="hljs-keyword">if</span> (dfX1 &lt;= <span class="hljs-number">180</span> &amp;&amp; dfX2 &gt;= <span class="hljs-number">180</span> &amp;&amp; dfX1 &lt; dfX2) {
                    <span class="hljs-keyword">var</span> dfRatio = (<span class="hljs-number">180</span> - dfX1) / (dfX2 - dfX1);
                    <span class="hljs-keyword">var</span> dfY = dfRatio * dfY2 + (<span class="hljs-number">1</span> - dfRatio) * dfY1;
                    poNewLS.push([first_pass[k - <span class="hljs-number">1</span>][<span class="hljs-number">0</span>] &gt; dfLeftBorderX ? <span class="hljs-number">180</span> : <span class="hljs-number">-180</span>, dfY]);
                    poNewLS = [];
                    poNewLS.push([first_pass[k - <span class="hljs-number">1</span>][<span class="hljs-number">0</span>] &gt; dfLeftBorderX ? <span class="hljs-number">-180</span> : <span class="hljs-number">180</span>, dfY]);
                    poMulti.push(poNewLS);
                } <span class="hljs-keyword">else</span> {
                    poNewLS = [];
                    poMulti.push(poNewLS);
                }
                poNewLS.push([dfX0, first_pass[k][<span class="hljs-number">1</span>]]);
            } <span class="hljs-keyword">else</span> {
                poNewLS.push([first_pass[k][<span class="hljs-number">0</span>], first_pass[k][<span class="hljs-number">1</span>]]);
            }
        }
    } <span class="hljs-keyword">else</span> {
        <span class="hljs-comment">// add normally</span>
        <span class="hljs-keyword">var</span> poNewLS0 = [];
        poMulti.push(poNewLS0);
        <span class="hljs-keyword">for</span> (<span class="hljs-keyword">var</span> l = <span class="hljs-number">0</span>; l &lt; first_pass.length; ++l) {
            poNewLS0.push([first_pass[l][<span class="hljs-number">0</span>], first_pass[l][<span class="hljs-number">1</span>]]);
        }
    }

    <span class="hljs-keyword">var</span> arc = <span class="hljs-keyword">new</span> Arc(<span class="hljs-keyword">this</span>.properties);
    <span class="hljs-keyword">for</span> (<span class="hljs-keyword">var</span> m = <span class="hljs-number">0</span>; m &lt; poMulti.length; ++m) {
        <span class="hljs-keyword">var</span> line = <span class="hljs-keyword">new</span> LineString();
        arc.geometries.push(line);
        <span class="hljs-keyword">var</span> points = poMulti[m];
        <span class="hljs-keyword">for</span> (<span class="hljs-keyword">var</span> j0 = <span class="hljs-number">0</span>; j0 &lt; points.length; ++j0) {
            line.move_to(points[j0]);
        }
    }
    <span class="hljs-keyword">return</span> arc;
};
</code></pre>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="../" class="navigation navigation-prev " aria-label="Previous page: INTRODUCE">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="chapter2.html" class="navigation navigation-next " aria-label="Next page: 2、COORDINATE MUTATION">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"1、MEASUREMENT","level":"1.2","depth":1,"next":{"title":"2、COORDINATE MUTATION","level":"1.3","depth":1,"path":"Chapter/chapter2.md","ref":"Chapter/chapter2.md","articles":[]},"previous":{"title":"INTRODUCE","level":"1.1","depth":1,"path":"README.md","ref":"README.md","articles":[]},"dir":"ltr"},"config":{"plugins":["sharing","livereload"],"styles":{"website":"./styles/website.css"},"pluginsConfig":{"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["weibo","google","twitter","weibo","instapaper"]},"livereload":{},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","author":"lijian","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"turf源码算法分析","language":"zh-hans","gitbook":"3.2.3","description":"turf源码算法分析"},"file":{"path":"Chapter/chapter1.md","mtime":"2020-06-19T06:08:39.000Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2021-03-28T04:08:06.675Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

